<!DOCTYPE html>
<html lang="zh" data-theme="light" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI汇报助理 - 智能登录</title>
    
    <!-- Tailwind CSS & Daisy UI -->
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/daisyui@4.12.10/dist/full.min.css" rel="stylesheet" type="text/css" />
    
    <!-- 自定义字体 -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <!-- 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
    
    <style>
        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            overflow: hidden;
        }
        
        .glass-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }
        
        .floating-shapes {
            position: absolute;
            width: 100%;
            height: 100%;
            overflow: hidden;
            z-index: -1;
        }
        
        .shape {
            position: absolute;
            opacity: 0.1;
            animation: float 6s ease-in-out infinite;
        }
        
        .shape:nth-child(1) {
            top: 10%;
            left: 10%;
            animation-delay: 0s;
        }
        
        .shape:nth-child(2) {
            top: 20%;
            right: 10%;
            animation-delay: 2s;
        }
        
        .shape:nth-child(3) {
            bottom: 20%;
            left: 20%;
            animation-delay: 4s;
        }
        
        @keyframes float {
            0%, 100% { transform: translateY(0px) rotate(0deg); }
            50% { transform: translateY(-20px) rotate(180deg); }
        }
        
        .input-focus:focus {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px rgba(102, 126, 234, 0.15);
        }
        
        .btn-hover:hover {
            transform: translateY(-2px);
            box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
        }
        
        .fade-in {
            animation: fadeIn 0.6s ease-out;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(30px); }
            to { opacity: 1; transform: translateY(0); }
        }
    </style>
</head>
<body class="flex items-center justify-center p-2">
    <!-- 浮动背景装饰 -->
    <div class="floating-shapes">
        <div class="shape w-16 h-16 bg-white rounded-full"></div>
        <div class="shape w-24 h-24 bg-white rounded-lg"></div>
        <div class="shape w-12 h-12 bg-white rounded-full"></div>
    </div>

    <div class="fade-in w-full max-w-sm">
        <div class="glass-card rounded-2xl p-6">
            <!-- Logo 和标题 -->
            <div class="text-center mb-4">
                <div class="w-16 h-16 bg-gradient-to-br from-purple-500 to-blue-600 rounded-xl flex items-center justify-center mx-auto mb-2">
                    <i class="fas fa-brain text-2xl text-white"></i>
                </div>
                <h1 class="text-2xl font-bold text-gray-800 mb-1">AI汇报助理</h1>
                <p class="text-sm text-gray-600">智能AI汇报系统</p>
            </div>

            <!-- 登录表单 -->
            <form id="loginForm" class="space-y-4">
                <!-- 用户名 -->
                <div class="form-control">
                    <label class="label py-1">
                        <span class="label-text text-sm font-medium text-gray-700">用户名</span>
                    </label>
                    <div class="relative">
                        <i class="fas fa-user absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 text-sm"></i>
                        <input 
                            type="text" 
                            name="userName" 
                            id="userName"
                            placeholder="请输入用户名"
                            class="input input-bordered w-full pl-10 pr-4 py-2 text-sm input-focus transition-all duration-200"
                            autocomplete="username"
                            required
                        />
                    </div>
                </div>

                <!-- 密码 -->
                <div class="form-control">
                    <label class="label py-1">
                        <span class="label-text text-sm font-medium text-gray-700">密码</span>
                    </label>
                    <div class="relative">
                        <i class="fas fa-lock absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 text-sm"></i>
                        <input 
                            type="password" 
                            name="passWord" 
                            id="passWord"
                            placeholder="请输入密码"
                            class="input input-bordered w-full pl-10 pr-4 py-2 text-sm input-focus transition-all duration-200"
                            autocomplete="current-password"
                            required
                        />
                    </div>
                </div>

                <!-- 验证码 -->
                <div class="grid grid-cols-12 gap-2">
                    <div class="col-span-8">
                        <label class="label py-1">
                            <span class="label-text text-sm font-medium text-gray-700">验证码</span>
                        </label>
                        <div class="relative">
                            <i class="fas fa-shield-alt absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 text-sm"></i>
                            <input 
                                type="text" 
                                name="code" 
                                id="code"
                                placeholder="验证码"
                                class="input input-bordered w-full pl-10 pr-4 py-2 text-sm input-focus transition-all duration-200"
                                autocomplete="off"
                                required
                            />
                        </div>
                    </div>
                    <div class="col-span-4">
                        <label class="label py-1">
                            <span class="label-text text-sm font-medium text-gray-700">&nbsp;</span>
                        </label>
                        <img 
                            id="codeImg" 
                            class="w-full h-10 rounded-md cursor-pointer border border-base-300 hover:border-primary transition-colors"
                            alt="验证码"
                            title="点击刷新验证码"
                        />
                    </div>
                </div>

                <!-- 记住密码 -->
                <div class="form-control">
                    <label class="label cursor-pointer justify-start py-1">
                        <input type="checkbox" name="remember-me" class="checkbox checkbox-primary checkbox-sm" />
                        <span class="label-text ml-2 text-sm text-gray-600">记住登录状态</span>
                    </label>
                </div>

                <!-- 登录按钮 -->
                <button 
                    type="submit" 
                    class="btn btn-primary btn-sm w-full btn-hover transition-all duration-200"
                    id="loginBtn"
                >
                    <span class="login-text">登录</span>
                    <span class="loading-text hidden">
                        <i class="fas fa-spinner fa-spin mr-1"></i>
                        登录中...
                    </span>
                </button>
            </form>

            <!-- 额外信息 -->
            <div class="mt-3 text-center">
                <p class="text-xs text-gray-500">
                    <i class="fas fa-info-circle mr-1"></i>
                    展示版本，不提供注册
                </p>
            </div>
        </div>
    </div>

    <!-- 引入必要的JS库 -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    
    <script th:inline="javascript">
        // 全局变量
        const ctx = [[${#httpServletRequest.getContextPath()}]];
        
        $(document).ready(function() {
            // 初始化验证码
            getImgCode();
            
            // 验证码刷新
            $('#codeImg').on('click', getImgCode);
            
            // 表单提交
            $('#loginForm').on('submit', function(e) {
                e.preventDefault();
                
                const btn = $('#loginBtn');
                const loginText = btn.find('.login-text');
                const loadingText = btn.find('.loading-text');
                
                // 验证表单
                const userName = $('#userName').val().trim();
                const passWord = $('#passWord').val().trim();
                const code = $('#code').val().trim();
                
                if (!userName || !passWord || !code) {
                    Swal.fire({
                        icon: 'warning',
                        title: '提示',
                        text: '请填写完整的登录信息',
                        timer: 2000,
                        showConfirmButton: false
                    });
                    return;
                }
                
                // 显示加载状态
                btn.prop('disabled', true);
                loginText.addClass('hidden');
                loadingText.removeClass('hidden');
                
                // 发送登录请求
                $.ajax({
                    url: ctx + '/login',
                    type: 'POST',
                    data: {
                        userName: userName,
                        passWord: passWord,
                        code: code,
                        'remember-me': $('input[name="remember-me"]').is(':checked') ? 'true' : 'false'
                    },
                    dataType: 'json',
                    success: function(response) {
                        if (response.code === 200) {
                            Swal.fire({
                                icon: 'success',
                                title: '登录成功',
                                text: '正在跳转...',
                                timer: 1000,
                                showConfirmButton: false,
                                willClose: () => {
                                    window.location.href = '/';
                                }
                            });
                        } else {
                            Swal.fire({
                                icon: 'error',
                                title: '登录失败',
                                text: response.message || '登录失败，请重试',
                                timer: 2000,
                                showConfirmButton: false
                            });
                            getImgCode();
                        }
                    },
                    error: function() {
                        Swal.fire({
                            icon: 'error',
                            title: '网络错误',
                            text: '网络连接失败，请检查网络后重试',
                            timer: 2000,
                            showConfirmButton: false
                        });
                    },
                    complete: function() {
                        // 恢复按钮状态
                        btn.prop('disabled', false);
                        loginText.removeClass('hidden');
                        loadingText.addClass('hidden');
                    }
                });
            });
            
            // 回车键登录
            $(document).on('keypress', function(e) {
                if (e.which === 13) {
                    $('#loginForm').submit();
                }
            });
            
            // 解决iframe框架问题
            if (window !== top) {
                top.location.href = location.href;
            }
        });
        
        // 获取验证码
        function getImgCode() {
            const url = ctx + '/getImgCode?' + new Date().getTime();
            const img = document.getElementById('codeImg');
            if (img) {
                img.src = url;
            }
        }
    </script>
</body>
</html>
